﻿<?php    
	include 'ChromePhp.php';
	require_once("class.phpmailer.php");
   
   ChromePhp::log("rec:".$_POST['rec']);
   ChromePhp::log("fName:".$_POST['fName']);
   ChromePhp::log("body:".$_POST['body']);
   ChromePhp::log("sub:".$_POST['sub']);
   
$uploadDir= 'upload';
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['rec'])) {
	
	//设置脚本运行时间
	set_time_limit(1500);
	 //参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名,文件名)
    smtp_mail($_POST['rec'], $_POST['sub'], $_POST['body'], NUll, "夏",$_POST['fName']);    
}else{
	ChromePhp::log("错误了");
	echo 2;
	exit;
}
	function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $sender_name,$file_name){
		ChromePhp::log("send");
		global $uploadDir;
		$mail = new PHPMailer();
		//$mail->SMTPDebug  = 2; 
        $mail->IsSMTP();                  // send via SMTP    
		//使用扣扣邮箱
        $mail->Host = "smtp.qq.com";   // SMTP servers    
        $mail->SMTPAuth = true;           // turn on SMTP authentication    
        $mail->Username = "604267811@qq.com";     // SMTP username  注意：普通邮件认证不需要加 @域名    
        $mail->Password = "bin86972793"; // SMTP password    
        $mail->From = "604267811@qq.com";      // 发件人邮箱   
        $mail->FromName = "=?utf-8?B?" . base64_encode("$sender_name") . "?=";  // 发件人ID
        $mail->CharSet = "UTF-8";   // 这里指定字符集！    
        $mail->Encoding = "base64";    
        $mail->AddAddress($sendto_email,null);  // 收件人邮箱和姓名    		
		//发送附件
		if($file_name!=null&&$file_name!=""){
			$mail->AddAttachment( $uploadDir.'/'.$file_name ,$file_name);
		}
		//邮件主题
        $mail->Subject ="=?utf-8?B?" . base64_encode("$subject") . "?="; 
        // 邮件内容    
        $mail->Body = $body;                                                                         
        $mail->AltBody ="text/html";    
        if(!$mail->Send())    
        {    
            echo "邮件发送有误 <p>";    
            echo "邮件错误信息: " . $mail->ErrorInfo;
            exit;    
        }    
        else {    
            echo 122;    
        }    
    }    
   
	
?>  
